const { getFolder } = require('../utils.js');

module.exports = {
  description: '创建组件',
  prompts: [
    {
      type: 'list',
      name: 'path',
      message: '请选择组件创建目录',
      choices: getFolder('src/components')
    },
    {
      type: 'input',
      name: 'name',
      message: '请输入文件名',
      validate: v => {
        if (!v || v.trim === '') {
          return '文件名不能为空'
        } else {
          return true
        }
      }
    }
  ],
  actions: data => {
    const name = '{{properCase name}}';
    const actions = [
      {
        type: 'add',
        path: `${data.path}/${name}.vue`,
        templateFile: 'plop-templates/component/index.hbs',
        data: {
          name,
        }
      }
    ]
    return actions
  }
}